package com.example.model.check_in;

import com.example.model.BaseEntity;
import com.example.model.payment.Payment;
import com.example.model.room.Room;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

public class CheckIn extends BaseEntity {

    private Long id;

    private List<CheckInGuest> guests;

    private Long roomNo;
    private Room room;

    private String paymentId;
    private Payment payment;

    private Integer status;  // 0:未支付，1:支付定金，2:完成支付
    private Integer scheduleFlag;

    private BigDecimal amount;

    private LocalDateTime checkInDate;
    private LocalDateTime checkOutDate;

    public CheckIn() {
    }

    public CheckIn(Long id) {
        this.id = id;
    }

    public CheckIn(Long id, OrderDo orderDo) {
        this.id = id;
        this.guests = orderDo.getCheckInGuests();
        this.status = 1;
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDateTime checkInTime = LocalDate.parse(orderDo.getCheckInDate(), formatter).atTime(12,0,0,0);
        setCheckInDate(checkInTime);
        setCheckOutDate(checkInTime.plusDays(orderDo.getCheckInDay()));
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<CheckInGuest> getGuests() {
        return guests;
    }

    public void setGuests(List<CheckInGuest> guests) {
        this.guests = guests;
    }

    public Room getRoom() {
        return room;
    }

    public void setRoom(Room room) {
        this.room = room;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Payment getPayment() {
        return payment;
    }

    public void setPayment(Payment payment) {
        this.payment = payment;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public LocalDateTime getCheckInDate() {
        return checkInDate;
    }

    public void setCheckInDate(LocalDateTime checkInDate) {
        this.checkInDate = checkInDate;
    }

    public LocalDateTime getCheckOutDate() {
        return checkOutDate;
    }

    public void setCheckOutDate(LocalDateTime checkOutDate) {
        this.checkOutDate = checkOutDate;
    }

    public Long getRoomNo() {
        return roomNo;
    }

    public void setRoomNo(Long roomNo) {
        this.roomNo = roomNo;
    }

    public String getPaymentId() {
        return paymentId;
    }

    public void setPaymentId(String paymentId) {
        this.paymentId = paymentId;
    }

    public Integer getScheduleFlag() {
        return scheduleFlag;
    }

    public void setScheduleFlag(Integer scheduleFlag) {
        this.scheduleFlag = scheduleFlag;
    }

    @Override
    public String toString() {
        return "CheckIn{" +
                "id=" + id +
                ", guests=" + guests +
                ", roomNo=" + roomNo +
                ", room=" + room +
                ", paymentId='" + paymentId + '\'' +
                ", payment=" + payment +
                ", status=" + status +
                ", amount=" + amount +
                ", checkInDate=" + checkInDate +
                ", checkOutDate=" + checkOutDate +
                '}';
    }
}
